home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / LCLINT2.SPK / test / test_b / c / sharing4 < prev    next >
Text File  |  1996-08-28  |  2KB  |  48 lines

  1. /*@only@*/   char *globonly1;
  2. /*@only@*/   char *globonly2;
  3. /*@only@*/   char *globonly3;
  4. /*@only@*/   char *globonly4;
  5. /*@only@*/   char *globonly5;
  6. /*@shared@*/ char *globshared1;
  7. /*@shared@*/ char *globshared2;
  8.  
  9. extern void free (/*@out@*/ /*@only@*/ void *s);
  10. extern /*@only@*/ char *string_copy (char *s) /*@modifies nothing;@*/ ;
  11.  
  12. int f(/*@only@*/ char *only1, /*@only@*/ char *only2, /*@only@*/ char *only3, 
  13.       char *temp1, /*@temp@*/ char *temp2, 
  14.       /*@shared@*/ char *shared1, /*@shared@*/ char *shared2)
  15. {
  16.   char *local1;
  17.  
  18.   globonly1 = only1;   /* 1. Only storage globonly1 not released before assignment */
  19.   free (globonly2);  
  20.   globonly2 = only2; 
  21.   free (globonly3);     /* okay...for now */
  22.  
  23.   globonly4 = shared1; /* 2. Only storage globonly4 not released before assignment
  24.               3. Shared storage assigned to only */
  25.   globshared1 = shared2;         
  26.   globshared1 = globshared2;
  27.   globshared1 = globonly5; /* 4. Only storage assigned to shared */
  28.  
  29.   local1 = globonly1;   
  30.   globshared1 = local1; /* 5. Only storage globonly1 assigned to shared (local1 aliases */
  31.                         /* 6. Kept storage only1 assigned to shared (local1 aliases */
  32.   globshared1 = string_copy (local1); /* 7. Only storage assigned to shared */
  33.   
  34.   globshared2 = temp2; /* 8. Temp storage temp2 assigned to shared */
  35.   globonly4 = temp1;   /* 9. Only storage globonly4 not released before assignment
  36.              10. Temp storage temp1 assigned to only: globonly4 = temp1 */
  37.  
  38.   free (shared1); /* 11. Shared storage shared1 passed as only param */
  39.   *only3 = 'a';
  40.   *shared2 = 'c';
  41.  
  42.   return 3; /* 12. Only storage only3 not released before return */
  43.         /* 13. Function returns with global globonly3 referencing released */
  44. }
  45.  
  46.  
  47.  
  48.